home *** CD-ROM | disk | FTP | other *** search
/ CDUTIL 13 / CDUTIL #13 Julio 1995.iso / windows / acadcom / ads / sample / ads_perr.c next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  9.4 KB  |  245 lines

  1. /* Next available MSG number is  89 */
  2.  
  3. /*
  4.    ADS_PERR.C
  5.  
  6.    Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994 by Autodesk, Inc.
  7.  
  8.    Permission to use, copy, modify, and distribute this software in 
  9.    object code form for any purpose and without fee is hereby granted, 
  10.    provided that the above copyright notice appears in all copies and 
  11.    that both that copyright notice and the limited warranty and 
  12.    restricted rights notice below appear in all supporting 
  13.    documentation.
  14.  
  15.    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  16.    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
  17.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  18.    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
  19.    UNINTERRUPTED OR ERROR FREE.
  20.  
  21.    Use, duplication, or disclosure by the U.S. Government is subject to 
  22.    restrictions set forth in FAR 52.227-19 (Commercial Computer 
  23.    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  24.    (Rights in Technical Data and Computer Software), as applicable.
  25.     
  26.    .
  27.  
  28.     ADS_PERR.C  -  ADS routine to print the error message
  29.                    associated with the value of "errno" upon failure
  30.                    of a call to AutoCAD.  This routine is meant to be
  31.                    invoked by other ADS programs, and contains a table
  32.                    of the current error messages as found in ol_errno.h.
  33.                    This routine is meant to parallel the Unix
  34.                    perror() function.
  35.  
  36.                    ads_perror() is a Lisp-callable or invokable function that
  37.                    takes an optional single argument and prints the message on
  38.                    the AutoCAD command line.  The syntax is:
  39.  
  40.                    (ads_perror "string")
  41.  
  42.                    The string is optional; if provided, it is printed on a
  43.                    separate line before the system error message.  To be of
  44.                    most use, the argument string should include the name of the
  45.                    program that incurred the error.  The error number is taken
  46.                    from the system variable "errno", which is set when most
  47.                    errors occur, but not cleared when non-erroneous calls are
  48.                    made.
  49.  */
  50.  
  51. #include  <stdio.h>
  52. #include  <string.h>
  53. #include  "adslib.h"
  54. #include  "ol_errno.h"
  55.  
  56. #define ELEMENTS(array) (sizeof(array) / sizeof((array)[0]))
  57.  
  58.  
  59. /* The error message array */
  60.  
  61. static struct {
  62.     int num;                          /* AutoCAD ERRNO code */
  63.     char *msg;                        /* Explanatory message */
  64. } errtbl[] = {
  65.     {  0, /*MSG88*/"Normal status; no error noted." },
  66.     {  1, /*MSG1*/"Invalid symbol table name." },
  67.     {  2, /*MSG2*/"Invalid name (entity or selection set) value." },
  68.     {  3, /*MSG3*/"Exceeded max number of selection sets." },
  69.     {  4, /*MSG4*/"Invalid selection set." },
  70.     {  5, /*MSG5*/"Improper use of Block Definition entity." },
  71.     {  6, /*MSG6*/"Improper use of Xref entity." },
  72.     {  7, /*MSG7*/"Entity selection failure by pick." },
  73.     {  8, /*MSG8*/"End of entity file." },
  74.     {  9, /*MSG9*/"End of Block Definition file." },
  75.     { 10, /*MSG10*/"Failure of eidlast." },
  76.     { 11, /*MSG11*/"Illegal entdel of Viewport." },
  77.     { 12, /*MSG12*/"Operation not allowed during PLINE." },
  78.     { 13, /*MSG13*/"Invalid handle." },
  79.     { 14, /*MSG14*/"Handles not enabled." },
  80.     { 15, /*MSG15*/"Invalid TRANS request." },
  81.     { 16, /*MSG16*/"Invalid space trans request." },
  82.     { 17, /*MSG17*/"Invalid use of deleted entity." },
  83.     { 18, /*MSG18*/"Invalid table name." },
  84.     { 19, /*MSG19*/"Invalid table function argument." },
  85.     { 20, /*MSG20*/"Attempt to set read-only variable." },
  86.     { 21, /*MSG21*/"Zero value invalid." },
  87.     { 22, /*MSG22*/"Value out of range." },
  88.     { 23, /*MSG23*/"Complex regen in progress." },
  89.     { 24, /*MSG24*/"Attempt to change entity type." },
  90.     { 25, /*MSG25*/"Bad layer name." },
  91.     { 26, /*MSG26*/"Bad linetype name." },
  92.     { 27, /*MSG27*/"Bad color name." },
  93.     { 28, /*MSG28*/"Bad text style name." },
  94.     { 29, /*MSG29*/"Bad shape name." },
  95.     { 30, /*MSG30*/"Bad field for entity type." },
  96.     { 31, /*MSG31*/"Attempted entmod of deleted entity." },
  97.     { 32, /*MSG32*/"Attempted entmod of SEQEND." },
  98.     { 33, /*MSG33*/"Attempt to change handle." },
  99.     { 34, /*MSG34*/"Illegal modification of viewport visibility." },
  100.     { 35, /*MSG35*/"Entity on locked layer." },
  101.     { 36, /*MSG36*/"Bad entity type." },
  102.     { 37, /*MSG37*/"Bad PLINE entity." },
  103.     { 38, /*MSG38*/"Incomplete complex entity in block." },
  104.     { 39, /*MSG39*/"Invalid block name field." },
  105.     { 40, /*MSG40*/"Duplicate block flag fields." },
  106.     { 41, /*MSG41*/"Duplicate block name fields." },
  107.     { 42, /*MSG42*/"Bad normal vector." },
  108.     { 43, /*MSG43*/"Missing block name." },
  109.     { 44, /*MSG44*/"Missing block flags." },
  110.     { 45, /*MSG45*/"Invalid anonymous block." },
  111.     { 46, /*MSG46*/"Invalid Block Definition entity." },
  112.     { 47, /*MSG47*/"Mandatory field missing." },
  113.     { 48, /*MSG48*/"Unrecognized extended data type." },
  114.     { 49, /*MSG49*/"Improper nesting of list in Xdata." },
  115.     { 50, /*MSG50*/"Improper location of APPID field." },
  116.     { 51, /*MSG51*/"Exceeded maximum Xdata size." },
  117.     { 52, /*MSG52*/"Entity selection failure by null response." },
  118.     { 53, /*MSG53*/"Duplicate application name in Xdata." },
  119.     { 54, /*MSG56*/"Attempt to make or modify Viewport entity." },
  120.     { 55, /*MSG57*/"Attempt to make an Xref or dependent symbol." },
  121.     { 56, /*MSG58*/"Bad ssget filter: unterminated clause." },
  122.     { 57, /*MSG59*/"Bad ssget filter: missing test operand." },
  123.     { 58, /*MSG60*/"Bad ssget filter: invalid test operation string." },
  124.     { 59, /*MSG61*/"Bad ssget filter: empty clause or improper nesting." },
  125.     { 60, /*MSG62*/"Bad ssget filter: begin/end clause mismatch." },
  126.     { 61, /*MSG63*/"Bad ssget filter: wrong number of XOR/NOT operands." },
  127.     { 62, /*MSG64*/"Bad ssget filter: maximum nesting level exceeded." },
  128.     { 63, /*MSG65*/"Bad ssget filter: invalid group code." },
  129.     { 64, /*MSG66*/"Bad ssget filter: invalid string test." },
  130.     { 65, /*MSG67*/"Bad ssget filter: invalid vector test." },
  131.     { 66, /*MSG68*/"Bad ssget filter: invalid real test." },
  132.     { 67, /*MSG69*/"Bad ssget filter: invalid integer test." },
  133.     { 68, /*MSG70*/"Digitizer isn't a tablet" },
  134.     { 69, /*MSG71*/"Tablet isn't calibrated." },
  135.     { 70, /*MSG72*/"Invalid arguments to (TABLET) function." },
  136.     { 71, /*MSG73*/"Not enough memory to allocate resbuf." },
  137.     { 72, /*MSG74*/"NULL Pointer was provided as an argument." },
  138.     { 73, /*MSG75*/"The specified file can't be opened." },
  139.     { 74, /*MSG76*/"The specified application is already loaded." },
  140.     { 75, /*MSG77*/"The maximum number of loaded ADS apps has been reached." },
  141.     { 76, /*MSG78*/"The specified application could not be executed." },
  142.     { 77, /*MSG79*/"The ADS app has an incompatible version number." },
  143.     { 78, /*MSG80*/"The ADS app is active or nested and can't be unloaded." },
  144.     { 79, /*MSG81*/"The ADS application refused to XUNLOAD." },
  145.     { 80, /*MSG82*/"The specified ADS application is not loaded." },
  146.     { 81, /*MSG83*/"Insuficient memory to load ADS application." },
  147.     { 82, /*MSG84*/"Invalid transformation matrix." },
  148.     { 83, /*MSG85*/"Invalid symbol name." },
  149.     { 84, /*MSG86*/"Invalid symbol value." },
  150.     { 85, /*MSG87*/"Operation not allowed while a dialogue box is active." },
  151. };
  152.  
  153. /*  Local function declarations */
  154.  
  155. int     ads_perror  _((void));
  156. void    main        _((int, char **));
  157. int     loadfuncs   _((void));
  158.  
  159.  
  160. /* MAIN -- the main routine */
  161. void
  162. /*FCN*/main(argc,argv)
  163.   int argc;
  164.   char *argv[];
  165. {
  166.     int stat;
  167.     short scode = RSRSLT;
  168.     char errmsg[80];
  169.  
  170.     ads_init(argc, argv);
  171.  
  172.     for ( ;; ) {
  173.  
  174.         if ((stat = ads_link(scode)) < 0) {
  175.             sprintf(errmsg,
  176.                     /*MSG54*/"ADS_PERR: bad status from ads_link() = %d\n",
  177.                     stat);
  178. #ifdef Macintosh
  179.             macalert(errmsg);
  180. #else
  181.             puts(errmsg);
  182.             fflush(stdout);
  183. #endif /* Macintosh */
  184.             exit(1);
  185.         }
  186.  
  187.         scode = RSRSLT;               /* default return value */
  188.  
  189.         switch (stat) {
  190.  
  191.         case RQXLOAD:
  192.             scode = loadfuncs() ? RSRSLT : -RSERR;
  193.             break;
  194.  
  195.         case RQSUBR:
  196.             ads_perror();
  197.             break;
  198.  
  199.         default:
  200.             break;
  201.         }
  202.     }
  203. }
  204.  
  205.  
  206. /* LOADFUNCS  --  Define external functions with AutoLISP */
  207. static int
  208. /*FCN*/loadfuncs()
  209. {
  210.     return (ads_defun(/*MSG0*/"ads_perror", 0) == RTNORM &&
  211.             ads_regfunc(ads_perror, 0) == RTNORM);
  212. }
  213.  
  214.  
  215. static int
  216. /*FCN*/ads_perror()
  217. {
  218.     int i;
  219.     struct resbuf *argl, errval;
  220.  
  221.     if (ads_getfuncode() != 0)        /* This is the ONLY function here */
  222.         return RSRSLT;
  223.  
  224.     if (ads_getvar(/*MSG0*/"ERRNO", &errval) == RTERROR)
  225.         return RSRSLT;
  226.  
  227.     argl = ads_getargs();
  228.     if (argl && argl->restype == RTSTR && strlen(argl->resval.rstring))
  229.         ads_printf("%s: ", argl->resval.rstring);
  230.  
  231.     for (i = 0; i < ELEMENTS(errtbl); i++)
  232.         if (errtbl[i].num == errval.resval.rint && errtbl[i].msg != NULL)
  233.             break;
  234.  
  235.     if (i < ELEMENTS(errtbl))
  236.         ads_printf("%s\n", errtbl[i].msg);
  237.     else
  238.         ads_printf("Unknown error code %d.\n", errval.resval.rint);
  239.  
  240.     ads_relrb(argl);
  241.     ads_retvoid();
  242.  
  243.     return RSRSLT;
  244. }
  245.